<?php 
class Brand_model extends CI_Model{
	/*
	*  use for table brand 
	*/	
	// get all from brand
	function get_all_brand($limit = 0 , $start = 0){
		$q = $this->db->select()
					  ->from('brand')
					  ->order_by('brand_name','asc')
					  ->limit($limit, $start)
					  ->get();				  
		$res['rows'] = $q->result();
		// get all no limit
		$q1 = $this->db->select()
					  ->from('brand')
					  ->order_by('brand_name','asc')
					  ->get();
		$res['all'] = $q1->result();
		// count
        $res['totalRows'] = $this->db->count_all('brand');
		
		return $res;
	}
	// get brabd by brand_id
	function get_brand_by_id($id=null){
		$q = $this->db->select()
					  ->from('brand')
					  ->where('brand_alias',$id)
					  ->get();				  
		$res = $q->row();
		return json_encode($res);
	}
	// check brand code 
	function check_brand_code($id=null){
		$q = $this->db->select('brand_alias')
					  ->from('brand')
					  ->where('brand_alias',$id)
					  ->get(); 
		if($q->row()){
			return true;	
		}else{
			return false;	
		}
	}
	// add new brand
	function add_brand($data){
			$this->db->insert('brand',$data);
			return;
	}
	// edit brand by id
	function edit_brand($id,$data){
			$this->db->where('brand_alias',$id) ;
			$this->db->update("brand",$data);
			return;
	}
	//delete brand by id
	function delete_brand($id){
		foreach($id as $item){
			$this->db->where('brand_alias',$item)
					 ->delete('brand');
		}
		return;
	}// ? delete in 
}